using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Data; 
using System.Data.SqlClient; 
using System.Data.SqlTypes; 
using SolucionUtiles; 
using SolucionEntidad; 
namespace SolucionDatos 
{ 
   public class ModuloDao 
    { 
        private SqlConnection cn; 
        public ModuloDao(SqlConnection cn) 
        { 
           this.cn = cn; 
        } 
        public void insert(Modulo obj)
        { 
           SqlCommand command = new SqlCommand("INSERT INTO modulo " + 
           "(idModulo,descripcion) VALUES" + 
           "(@idModulo,@descripcion)", this.cn); 

command.Parameters.Add(new SqlParameter("@idModulo", obj.idModulo)); 
command.Parameters.Add(new SqlParameter("@descripcion", obj.descripcion)); 
command.ExecuteNonQuery(); 
} 
  		public void update(Modulo obj) 
    	{ 
        	SqlCommand command = new SqlCommand("UPDATE Modulo " + 
			" SET " + 
"descripcion=@descripcion" + 
 " WHERE " + 
"idModulo=@idModulo" 
,this.cn); 
command.Parameters.Add(new SqlParameter("@idModulo", obj.idModulo)); 
command.Parameters.Add(new SqlParameter("@descripcion", obj.descripcion)); 
command.ExecuteNonQuery(); 
} 
       public void delete(Modulo obj){ 
SqlCommand command = new SqlCommand("DELETE FROM modulo WHERE "  
 +"idModulo=@idModulo" 
, this.cn); 
command.Parameters.Add(new SqlParameter("@idModulo", obj.idModulo)); 
command.ExecuteNonQuery(); 
} 
        public Modulo get(Modulo obj) 
{ 
   Modulo record = null; 
    SqlCommand command = new SqlCommand("SELECT idModulo,descripcion FROM modulo where " 
 +"idModulo=@idModulo" 
, this.cn); 
command.Parameters.Add(new SqlParameter("@idModulo", obj.idModulo)); 

    SqlDataReader dr = command.ExecuteReader();
dr.Read(); 
record = new Modulo(); 
if (dr["idModulo"] == DBNull.Value) { record.idModulo = SqlInt32.Null; } else { record.idModulo = (Int32)dr["idModulo"]; } 
if (dr["descripcion"] == DBNull.Value) { record.descripcion = SqlString.Null; } else { record.descripcion = (String)dr["descripcion"]; } 
this.cn.Close(); 
return record; 
} 
     public List<Modulo> getList() 
{ 
   List<Modulo> list = new List<Modulo>(); 
    SqlCommand command = new SqlCommand("SELECT idModulo,descripcion FROM modulo", this.cn); 
    SqlDataReader dr = command.ExecuteReader(); 
    while (dr.Read()) 
    { 
Modulo obj = new Modulo(); 
if (dr["idModulo"] == DBNull.Value) { obj.idModulo = SqlInt32.Null; } else { obj.idModulo = (Int32)dr["idModulo"]; } 
if (dr["descripcion"] == DBNull.Value) { obj.descripcion = SqlString.Null; } else { obj.descripcion = (String)dr["descripcion"]; } 
list.Add(obj); 
} 
return list; 
} 
} 
} 
